

Date.prototype.format = function(format) {

    function getYearWeek(date){
        var date2=new Date(date.getFullYear(), 0, 1);
        var day1=date.getDay();
        if(day1==0) day1=7;
        var day2=date2.getDay();
        if(day2==0) day2=7;
        d = Math.round((date.getTime() - date2.getTime()+(day2-day1)*(24*60*60*1000)) / 86400000);
        return Math.ceil(d /7) - 1;
    }

    var w = this.getDay(),
        d = this.getDate();
    if(w==0){
        w=7;
    }
    var o = {
        "M+" : this.getMonth()+1, //month
        "d+" : this.getDate(),    //day
        "h+" : this.getHours(),   //hour
        "m+" : this.getMinutes(), //minute
        "s+" : this.getSeconds(), //second
        "q+" : Math.floor((this.getMonth()+3)/3),  //quarter
        "S" : this.getMilliseconds(), //millisecond,
        "W": getYearWeek(this)
    }


    if(/(y+)/.test(format)) format=format.replace(RegExp.$1,
        (this.getFullYear()+"").substr(4 - RegExp.$1.length));
    for(var k in o)if(new RegExp("("+ k +")").test(format))
        format = format.replace(RegExp.$1,
            RegExp.$1.length==1 ? o[k] :
                ("00"+ o[k]).substr((""+ o[k]).length));
    return format;
}


$.ajax({
    type:"POST",
    url:"http://vadmin.o-home.cc/bgyvapp/com.vplus.login.loginex.flow/com.vplus.kaoqin.punch.getCurTime.biz.ext",
    success(res){
        $("#now").text(res.time)
    }
})
var kqdate = "";
$.ajax({
    type:"POST",
    url:"http://vadmin.o-home.cc/bgyvapp/com.vplus.kaoqin.punch.jungleIsAblePunch.biz.ext",
    headers:{
        "content-type":"application/x-www-form-urlencoded;charset=utf-8"
    },
    data:{
        userId:4502,
    },
    success(res){
        console.log(res)
        kqdate = res.kqdate;
    }
})

var judgeDay = false;
$.ajax({
    type:"POST",
    url:"http://vadmin.o-home.cc/bgyvapp/com.vplus.kaoqin.mp_interface.judgeIsDayOff.biz.ext",
    headers:{
        "content-type":"application/x-www-form-urlencoded;charset=utf-8"
    },
    data:{
        userId:4502,
        date:new Date().format("yyyyMMdd")
    },
    success(res){
        console.log(res)
        if(res.message=="Y"){
            judgeDay = true
        }
    }
})


var week = new Date().getDay();

var uuid = "3FE62090-B609-47A6-BFC2-3DD38176915Aiphone";
// var uuid = "2CA42F85-8A36-4EE2-A349-FA3FB8F8F8F8iPhone";

var defalutId = localStorage.getItem('myIdentity');

$("#userId").val(defalutId?defalutId:'')


function on() {
    var url = "http://vadmin.o-home.cc/bgyvapp/com.vplus.kaoqin.punch.punchOn.biz.ext";
    var data = {
        userId:$("#userId").val(),
        punchjindu: 113.392283,
        punchweidu: 23.12381,
        punchdistance:200,
        kqareaid:141,
        phonesequence:uuid,
        purl:"",
        puncharea:"广州市天河区黄埔大道中552号"
    }
    if(week==6||week==0||judgeDay==true){
        url = "http://vadmin.o-home.cc/bgyvapp/com.vplus.kaoqin.punch.dayPunch.biz.ext";
        data.punchtype = "on"
        data.kqdate = kqdate
    }
    $.ajax({
        type:"POST",
        url,
        headers:{
            "content-type":"application/x-www-form-urlencoded;charset=utf-8"
        },
        data,
        success(res){
            alert(res.msg)
            localStorage.setItem('myIdentity', $("#userId").val());
            log()
            _czc.push(["_trackEvent","on",$("#userId").val()]);
        }
    })
}
function off() {
    var url = "http://vadmin.o-home.cc/bgyvapp/com.vplus.kaoqin.punch.punchOff.biz.ext";
    var data = {
        userId:$("#userId").val(),
        punchjindu: 113.392283,
        punchweidu: 23.12381,
        punchdistance:200,
        kqareaid:141,
        phonesequence:uuid,
        purl:"",
        puncharea:"广州市天河区黄埔大道中552号"
    }
    if(week==6||week==0||judgeDay==true){
        url = "http://vadmin.o-home.cc/bgyvapp/com.vplus.kaoqin.punch.dayPunch.biz.ext";
        data.punchtype = "off"
        data.kqdate = kqdate
    }
    $.ajax({
        type:"POST",
        url,
        headers:{
            "content-type":"application/x-www-form-urlencoded;charset=utf-8"
        },
        data,
        success(res){

            alert(res.msg)
            localStorage.setItem('myIdentity', $("#userId").val());
            if($("#userId").val()!=4502){
                Liujian("off")
            }
            log()
            _czc.push(["_trackEvent","off",$("#userId").val()]);
        }
    })
}
function log() {
    $.ajax({
        type:"POST",
        url:"http://vadmin.o-home.cc/bgyvapp/com.vplus.kaoqin.mp_interface.daKaInfo.biz.ext",
        headers:{
            "content-type":"application/x-www-form-urlencoded;charset=utf-8"
        },
        data:{
            userId:$("#userId").val()
        },
        success(res){
            $("#logBoard").html(JSON.stringify(res))
        }
    })
}

function Liujian(type) {
    if(type=="off"){
        $.ajax({
            type:"POST",
            url:"http://vadmin.o-home.cc/bgyvapp/com.vplus.kaoqin.punch.punchOff.biz.ext",
            headers:{
                "content-type":"application/x-www-form-urlencoded;charset=utf-8"
            },
            data:{
                userId:4502,
                punchjindu: 113.392283,
                punchweidu: 23.12381,
                punchdistance:200,
                kqareaid:141,
                phonesequence:uuid,
                purl:"",
                puncharea:"广州市天河区黄埔大道中552号"
            },
            success(res){
            }
        })
    }
    if(type=="on"){
        $.ajax({
            type:"POST",
            url:"        http://vadmin.o-home.cc/bgyvapp/com.vplus.kaoqin.punch.punchOn.biz.ext",
            headers:{
                "content-type":"application/x-www-form-urlencoded;charset=utf-8"
            },
            data:{
                userId:4502,
                punchjindu: 113.392283,
                punchweidu: 23.12381,
                punchdistance:200,
                kqareaid:141,
                phonesequence:"3FE62090-B609-47A6-BFC2-3DD38176915Aiphone",
                purl:"",
                puncharea:"广州市天河区黄埔大道中552号"
            },
            success(res){
            }
        })
    }
}



